<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>开关</title>

</head>
<body>
<img id="light" src="img/off.gif"/>
<script>
    var light = document.getElementById("light");
    var flag = false;
    light.onclick = function () {

        if (flag) {
            light.src = "img/on.gif";
            flag = false;
        } else {
            light.src = "img/off.gif";
            flag = true;
        }
    }

</script>


</body>
</html>